<template>
  <div style="background: #e8f1f8">
    <div class="det_tab">
      <div class="det_tab_item">
        <div style="margin-bottom: 10px;padding-left: 10px;">记录详情</div>
        <van-cell-group :border="border">
          <eagle-input
            label="事故名称"
            class="input_text event_name"
            :value="form.AccidentName"
            type="textarea"
            rows="1"
            autosize
            readonly
            @click="view(form.Accident_RMID)"
          />
          <eagle-input
            label="责任人"
            class="input_text"
            :value="form.RectificationPeople"
            readonly
          />
          <eagle-input
            label="完成日期"
            class="input_text"
            :value="form.FinishDate | formatDate"
            readonly
          />
        </van-cell-group>
      </div>
      <div
        class="det_tab_item"
        style="margin-top: 10px"
      >
        <div class="operate_det">
          <div style="margin-bottom: 10px">操作历史记录</div>
          <div class="operate_list">
            <eagle-row class="operate_row_first">
              <eagle-col span="2">序号</eagle-col>
              <eagle-col
                offset="1"
                span="5"
              >整改操作</eagle-col>
              <eagle-col
                offset="2"
                span="5"
              >操作说明</eagle-col>
            </eagle-row>
            <eagle-row
              v-for="(item, index) in form.CorrectiveLogList"
              :key="index"
              class="operate_row"
            >
              <eagle-col span="2">{{ index + 1 }}</eagle-col>
              <eagle-col
                offset="1"
                span="5"
              >{{ getTtype(item.OperateType) }}
              </eagle-col>
              <eagle-col span="16">{{ item.OperateLog }}
                <div v-if="item.Attachs!=null">
                  <!-- <eagle-image-preview :images="item.Attachs"></eagle-image-preview> -->
                  <eagle-image-preview :images="item.Attachs"></eagle-image-preview>
                </div>
              </eagle-col>
            </eagle-row>
          </div>
        </div>
      </div>
      <div
        class="det_tab_item"
        style="margin-top: 10px"
        v-if="this.$route.query.state== 'RectificationMeasures'"
      >
        <div class="operate_det">
          <div style="margin-bottom: 10px">整改操作</div>
          <van-field
            class="input_text"
            name="uploader"
            label="整改图片"
            required
          >
            <template #input>
              <eagle-image-uploader :images.sync="editForm.Attachs"></eagle-image-uploader>

            </template>
          </van-field>
          <eagle-input
            v-model="editForm.CorrectiveRemarks"
            autosize
            label="整改说明"
            type="textarea"
            isInputText
            placeholder="请输入整改说明"
          />
        </div>
        <div style="margin: 16px">
          <van-button
            round
            block
            type="info"
            @click="submit"
          >提交</van-button>
        </div>
      </div>
      <div
        class="det_tab_item"
        style="margin-top: 10px"
        v-if="this.$route.query.state== 'ForAcceptance'"
      >
        <div class="operate_det">
          <div style="margin-bottom: 10px">验收</div>
          <van-field
            class="input_text"
            name="AcceptanceDecision"
            label="判定"
            required
          >
            <template #input>
              <van-radio-group
                v-model="AcceptanceDecision"
                direction="horizontal"
              >
                <van-radio
                  name="Y"
                  style="margin: 0 10px 10px 0"
                >通过</van-radio>
                <van-radio
                  name="N"
                  style="margin: 0 10px 10px 0"
                >不通过</van-radio>
              </van-radio-group>
            </template>
          </van-field>
          <eagle-input
            v-model="editForm.Remarks"
            v-show="AcceptanceDecision=='Y' || AcceptanceDecision==null"
            autosize
            label="验收意见"
            type="textarea"
            placeholder="请输入验收意见"
          />
          <eagle-input
            v-model="editForm.Remarks"
            required
            autosize
            label="验收意见"
            v-show="AcceptanceDecision=='N'"
            type="textarea"
            placeholder="请输入验收意见"
          />
        </div>
        <div style="margin: 16px">
          <van-button
            round
            block
            type="info"
            @click="submitAcceptanceDecision"
          >提交</van-button>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { upload } from "@/api/common";
import { deepClone } from "@/utils";
export default {
  data() {
    return {
      id: this.$route.query.id,
      border: false,
      CorrectiveUserName: "",
      CorrectiveChnName: "",
      form: {},
      AcceptanceDecision: "Y",
      imgs: [],
      editForm: {},
      remarks: "",
      radio: "N",
    };
  },
  created() {
    this.geDetail();
  },
  activated() {
    if (this.$route.params.Operator) {
      this.CorrectiveUserName = this.$route.params.Operator;
      this.CorrectiveChnName = this.$route.params.OperatorName;
    }
  },
  methods: {
    onOversize(file) {
      Toast("文件大小不能超过 2M");
    },
    afterRead(file) {
      let params = new FormData(); //创建form对象
      params.append("file", file.file);
      upload(params)
        .then((res) => {
          res.data.forEach((item) => {
            this.imgs.push(item.FilePath);
          });
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
    //获取详情
    geDetail() {
      let _this = this;
      _this.$axios
        .get("/WhInvestigationReportLog/GetWHInvestigationReportLog", {
          params: { id: _this.$route.query.id },
        })
        .then((res) => {
          _this.form = res.data;
          _this.editForm = deepClone(res.data);
        });
    },
    submit() {
      //整改
      if (!this.editForm.Attachs) {
        this.$toast("请上传整改图片");
        return;
      }
      let param = {
        ID: this.$route.query.id,
        CorrectiveRemarks: this.editForm.CorrectiveRemarks,
        //Attachs: this.imgs.join(";"),
        Attachs: this.editForm.Attachs,
      };
      let _this = this;
      _this.$axios
        .post("/WhInvestigationReportLog/ConfirmCorrective", param)
        .then((res) => {
          _this.$toast("保存成功");
          // this.loading = false
          _this.$router.goRefresh(-1);
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
    submitAcceptanceDecision() {
      if (this.AcceptanceDecision == "N" && !this.editForm.Remarks) {
        this.$toast("请输入验收意见");
        return;
      }
      if (this.AcceptanceDecision == "Y") {
        this.confirmVerify();
      } else {
        this.backVerify();
      }
    },
    confirmVerify() {
      //通过
      let param = {
        ID: this.$route.query.id,
        Remarks: this.editForm.Remarks,
      };
      let _this = this;
      _this.$axios
        .post("/WhInvestigationReportLog/ConfirmVerify", param)
        .then((res) => {
          _this.$toast("保存成功");
          // this.loading = false
          _this.$router.goRefresh(-1);
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
    backVerify() {
      //退回
      let param = {
        ID: this.$route.query.id,
        Remarks: this.editForm.Remarks,
      };
      let _this = this;
      _this.$axios
        .post("/WhInvestigationReportLog/BackVerify", param)
        .then((res) => {
          _this.$toast("保存成功");
          // this.loading = false
          _this.$router.goRefresh(-1);
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
    getTtype(val) {
      if (val == "Submit") {
        return "提交";
      } else if (val == "Pending") {
        return "待处理";
      } else if (val == "Corrective") {
        return "整改完成";
      } else if (val == "BackVerify") {
        return "验收退回";
      } else if (val == "Verify") {
        return "验收完成";
      }
    },
    view(item) {
      this.$router.push({
        path: "/whInvestigationReportView",
        query: { id: item },
      });
    },
  },
};
</script>

<style lang="less">
.event_name .van-field__control {
  color: #337ab7 !important;
}
/*
        .main {
            height: 100vh;
        }
    */

.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/

  .det_top {
    display: flex;
    justify-content: space-between;

    .dep_top_img {
      height: 20px;
      width: 20px;
      margin-right: 5px;
    }
  }

  .det_name {
    margin-top: 20px;
    text-align: center;
  }

  .det_location {
    text-align: center;
    margin-bottom: 20px;
  }
}

.det_tab {
  padding: 10px;
  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}

.text_box {
  padding: 10px;
  border-radius: 5px;
  /*background-color: #e8f1f8;*/
  margin-bottom: 10px;

  .text_top {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    .top_link {
      color: #1989fa;
    }
  }

  .text_item {
    display: flex;
    justify-content: space-between;
    margin-left: 10px;

    .item_link {
      color: #1989fa;
    }
  }

  .text_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      img {
        height: 25px;
        width: 25px;
        margin-bottom: 10px;
      }
    }
  }

  .text_history {
    display: flex;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .text_member {
    color: #1989fa;
    margin-bottom: 10px;
  }

  .text_total_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      .img_item_top {
        display: flex;
        vertical-align: middle;
        margin-bottom: 10px;
      }
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .text_record_list {
    .list_row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      > div {
        width: 33.3%;
      }
      .row_center {
        text-align: center;
      }
      .row_right {
        text-align: right;
      }
    }
  }
}

.operate_det {
  background-color: #fff;
  padding: 10px;
  .operate_list {
    font-size: 12px;
    border: 1px solid #e8f1f8;
    .operate_row_first {
      padding: 10px;
      background-color: #e8f1f8;
      border-bottom: 1px solid #e8f1f8;
      margin-bottom: 10px;
    }
    .operate_row {
      padding: 10px;
      border-bottom: 1px solid #e8f1f8;
      line-height: 16px;
    }
  }
}
</style>
